#include "console.h"

Console::Console(QWidget *parent) :
    QListWidget(parent)
{
    for (int i = 0; i < 20; i++) {
        addItem("");
        item(count()-1)->setBackground(Qt::black);
    }

    connect(this->verticalScrollBar(), SIGNAL(rangeChanged(int,int)), this, SLOT(setSlideDown()));
}

void Console::enterMessage(QString str, Qt::GlobalColor brush) {

    delete item(0);

    QString msg;
    msg = '[' + QTime::currentTime().toString() + "]: " + str;

    addItem(msg);
    item(count()-1)->setForeground(brush);
    item(count()-1)->setBackground(Qt::black);

    setSlideDown();

}


void Console::setSlideDown() {
    verticalScrollBar()->setSliderPosition(verticalScrollBar()->maximum());
}

